package com

import (
	"net"
	"alex/msc/helper"
)

// Prepares and sends the UDP packet to the specified IP address and port
// Signaling and Management are OPTIONAL!
func MessageSender(ipAddress, port string, message []byte) {
	address := ipAddress + ":" + port

	udpAddr, err := net.ResolveUDPAddr("udp", address)
	helper.ErrHandling(err)

	connection, err := net.DialUDP("udp", nil, udpAddr)
	helper.ErrHandling(err)

	handleServer(connection, message)
}

// Writes 'on' the connection
func handleServer(connection *net.UDPConn, msg []byte) {
	//var buffer [512]byte
	//_, err := connection.Write([]byte("writening going on"))
	_, err := connection.Write(msg)
	helper.ErrHandling(err)
}
